{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第四次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer4文件夹下，谢绝交到master下\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在10月30日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名  颜丙琦\n",
    "+ 学号  0165199"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一\n",
    "一般的歌，分为主歌和副歌部分。副歌有重复，对比两大功能。这就是A－B的基本曲式形式结构。  \n",
    "请找一首你的主打歌，把歌词打印出来，重复的副歌部分，请写一个函数，调用函数打印出来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "每天起床第一句 先给自己打个气\n",
      "每次多吃一粒米 都要说声对不起\n",
      "魔镜魔镜看看我 我的锁骨在哪里\n",
      "美丽 我要美丽 我要变成万人迷\n",
      "Pose pose\n",
      "我要变成万人迷\n",
      "Pose pose\n",
      "为了变成小蛮腰 天天提着一口气\n",
      "为了穿上比基尼 吃草吃成沙拉精\n",
      "天生丽质难自弃 可惜吃啥我都不腻\n",
      "努力 我要努力 我要变成万人迷\n",
      "\n",
      "\n",
      "Wow\n",
      "卡路里卡路里卡路\n",
      "卡路里卡路里卡路\n",
      "卡路里卡路里卡路\n",
      "卡路里卡路里卡路\n",
      "卡路里我的天敌\n",
      "燃烧我的卡路里\n",
      "拜拜 甜甜圈 珍珠奶茶方便面\n",
      "火锅米饭大盘鸡\n",
      "拿走拿走别客气\n",
      "拜拜 咖啡因 戒掉可乐戒油腻\n",
      "沙发外卖玩游戏\n",
      "别再熬夜伤身体\n",
      "来来 后转体 高温瑜伽仰卧起\n",
      "动感单车普拉提\n",
      "保温杯里泡枸杞\n",
      "来来 深呼吸 晨跑夜跑游几米\n",
      "平板哑铃划船机 不达目的不放弃\n",
      "\n",
      "奇了怪了 小的时候明明是 妈妈说\n",
      "吃光盘中餐粒粒 皆辛苦\n",
      "直到最爱的裙子的扣子都系不上了\n",
      "原来吃得掉 甩不掉 更辛苦\n",
      "希望 体重 秤是坏的\n",
      "帅哥 爱唐代的\n",
      "不如跟着节奏没在怕的 努努力\n",
      "别让卡路里里卡路里 卡住你\n",
      "不达目的不放弃\n",
      "\n",
      "Wow\n",
      "卡路里卡路里卡路\n",
      "卡路里卡路里卡路\n",
      "卡路里卡路里卡路\n",
      "卡路里卡路里卡路\n",
      "卡路里我的天敌\n",
      "燃烧我的卡路里\n",
      "拜拜 甜甜圈 珍珠奶茶方便面\n",
      "火锅米饭大盘鸡\n",
      "拿走拿走别客气\n",
      "拜拜 咖啡因 戒掉可乐戒油腻\n",
      "沙发外卖玩游戏\n",
      "别再熬夜伤身体\n",
      "来来 后转体 高温瑜伽仰卧起\n",
      "动感单车普拉提\n",
      "保温杯里泡枸杞\n",
      "来来 深呼吸 晨跑夜跑游几米\n",
      "平板哑铃划船机 不达目的不放弃\n",
      "\n"
     ]
    }
   ],
   "source": [
    "def verse():\n",
    "    print(\"\"\"\\nWow\n",
    "卡路里卡路里卡路\n",
    "卡路里卡路里卡路\n",
    "卡路里卡路里卡路\n",
    "卡路里卡路里卡路\n",
    "卡路里我的天敌\n",
    "燃烧我的卡路里\n",
    "拜拜 甜甜圈 珍珠奶茶方便面\n",
    "火锅米饭大盘鸡\n",
    "拿走拿走别客气\n",
    "拜拜 咖啡因 戒掉可乐戒油腻\n",
    "沙发外卖玩游戏\n",
    "别再熬夜伤身体\n",
    "来来 后转体 高温瑜伽仰卧起\n",
    "动感单车普拉提\n",
    "保温杯里泡枸杞\n",
    "来来 深呼吸 晨跑夜跑游几米\n",
    "平板哑铃划船机 不达目的不放弃\n",
    "\"\"\")\n",
    "print(\"\"\"每天起床第一句 先给自己打个气\n",
    "每次多吃一粒米 都要说声对不起\n",
    "魔镜魔镜看看我 我的锁骨在哪里\n",
    "美丽 我要美丽 我要变成万人迷\n",
    "Pose pose\n",
    "我要变成万人迷\n",
    "Pose pose\n",
    "为了变成小蛮腰 天天提着一口气\n",
    "为了穿上比基尼 吃草吃成沙拉精\n",
    "天生丽质难自弃 可惜吃啥我都不腻\n",
    "努力 我要努力 我要变成万人迷\n",
    "\"\"\")\n",
    "verse()\n",
    "print(\"\"\"奇了怪了 小的时候明明是 妈妈说\n",
    "吃光盘中餐粒粒 皆辛苦\n",
    "直到最爱的裙子的扣子都系不上了\n",
    "原来吃得掉 甩不掉 更辛苦\n",
    "希望 体重 秤是坏的\n",
    "帅哥 爱唐代的\n",
    "不如跟着节奏没在怕的 努努力\n",
    "别让卡路里里卡路里 卡住你\n",
    "不达目的不放弃\"\"\")\n",
    "verse()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二\n",
    "请写一个函数，能够计算均值、样本方差和n(自己写公式哦)。\n",
    "每次输入十个以上的数字，能够输出上述三个统计量。\n",
    "至少调用两次。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "均值为5.5\n",
      "样本方差为8.25\n",
      "n为10\n",
      "\n",
      "均值为10.4\n",
      "样本方差为15.64\n",
      "n为10\n"
     ]
    }
   ],
   "source": [
    "def statistic(*arg):\n",
    "    mean=0\n",
    "    var=0\n",
    "    sum=0\n",
    "    count=0\n",
    "    for value in arg:\n",
    "        count+=1\n",
    "        sum+=value\n",
    "    mean=sum/count\n",
    "    square=0\n",
    "    for value in arg:\n",
    "        square+=(value-mean)**2\n",
    "    var=square/count\n",
    "    print(\"\\n均值为%s\"% mean)\n",
    "    print(\"样本方差为%s\"% var)\n",
    "    print(\"n为%s\"% count)\n",
    "statistic(1,2,3,4,5,6,7,8,9,10)\n",
    "statistic(5,6,7,8,9,11,12,13,15,18)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三\n",
    "刚才那个函数，默认的是输出均值、样本方差和n，请在后面添加一个关键词参数，让这个函数可以选择输出样本标准差或方差。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "请输入您选择的统计量，其中1为标准差，其他数字为方差：\n",
      "0\n",
      "样本标准差是:2.7386127875258306\n",
      "均值为6.0\n",
      "n为9\n",
      "\n",
      "请输入您选择的统计量，其中1为标准差，其他数字为方差：\n",
      "1\n",
      "样本方差是：15.5\n",
      "均值为11.0\n",
      "n为9\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "def statistic(i,*arg):\n",
    "    mean=0\n",
    "    var=0\n",
    "    sum=0\n",
    "    count=0\n",
    "    for value in arg:\n",
    "        count+=1\n",
    "        sum+=value\n",
    "    mean=sum/count\n",
    "    square=0\n",
    "    standard=0\n",
    "    for value in arg:\n",
    "        square+=(value-mean)**2\n",
    "    var=square/(count-1)\n",
    "    standard=var**(1/2)\n",
    "    print(\"\\n请输入您选择的统计量，其中1为标准差，其他数字为方差：\")\n",
    "    i=int(input())    \n",
    "    if i==0:\n",
    "        print(\"样本标准差是:%s\" % standard)\n",
    "    else:\n",
    "        print(\"样本方差是：%s\" % var)\n",
    "    print(\"均值为%s\"% mean)\n",
    "    print(\"n为%s\"% count)\n",
    "statistic(1,2,3,4,5,6,7,8,9,10)\n",
    "statistic(5,6,7,8,9,11,12,13,15,18)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目四\n",
    "刚才那个函数，请再增加三个关键词参数，让这个参数可以选择输出均值的标准误、最大值、最小值或不输出这三个统计量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import math\n",
    "def statistic(a,b,c,*arg):\n",
    "    sum=0\n",
    "    count=0\n",
    "    for value in arg:\n",
    "        count+=1\n",
    "        sum+=value\n",
    "    mean=sum/count\n",
    "    square=0\n",
    "    standard=0\n",
    "    for value in arg:\n",
    "        square+=(value-mean)**2\n",
    "    var=square/(count-1)\n",
    "    standard=var**(1/2)\n",
    "    error=standard/(count**(1/2))\n",
    "    print(\"如果您选择输出均值的标准误，请输入1：\")\n",
    "    a=int(input())\n",
    "    if a==1:\n",
    "        print(\"标准误为%s\"% error)\n",
    "    else:\n",
    "        print(\"不输出\")\n",
    "    print(\"如果您选择输出均值的最大值，请输入2：\")\n",
    "    b=int(input())\n",
    "    if b==2:\n",
    "        print(\"最大值为%s\"% max(arg))\n",
    "    else:\n",
    "        print(\"不输出\")\n",
    "    print(\"如果您选择输出均值的最小值，请输入3：\")\n",
    "    c=int(input())\n",
    "    if c==3:\n",
    "        print(\"最小值为%s\"% min(arg))\n",
    "    else:\n",
    "        print(\"不输出\")\n",
    "statistic(1,2,3,4,5,6,7,8,9,10)\n",
    "statistic(5,6,7,8,9,11,12,13,15,18)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
